<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" >
            <el-form-item label="被取保候审人(被行政拘留人)" prop="hsr">
                <el-input v-model="queryParams.hsr" placeholder="请输入被取保候审人(被行政拘留人)" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="是否超期">
                <el-select v-model="queryParams.isOverdue" placeholder="请选择" @change="overdueChange">
                    <el-option v-for="(item, index) in [{ label: '已超期' }, { label: '未超期' }]" :key="index"
                        :label="item.label" :value="item.label">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="剩余天数<" v-if="sytsVisabled" :required="sytsVisabled">
                <el-select v-model="queryParams.overdueDay" placeholder="请选择" width="50">
                    <el-option
                        v-for="(item, index) in [{ label: '7' }, { label: '15' }, { label: '30' }, { label: '60' }, { label: '90' }]"
                        :key="index" :label="item.label" :value="item.label">
                    </el-option>
                </el-select>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <!-- <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <div style="margin-top: 5px;">
                    <el-radio v-model="queryParams.msshzt" :label="2">已通过</el-radio>
                    <el-radio v-model="queryParams.msshzt" :label="3">未通过</el-radio>
                </div>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row> -->

        <el-table v-loading="loading" height="650" :data="bzjtableList" :row-class-name="tableRowClassName"
            @current-change="tableCurrentChange">
            <el-table-column label="预警状态" align="center" width="150">
                <template slot-scope="scope">
                    <el-tag :type="`${scope.row.cqzt == 'CQ' ? 'danger' : 'info'}`">{{ scope.row.cqzt == 'CQ' ?
                        `已超期${scope.row.cqts}天` : `剩余${scope.row.cqts}天超期`}}</el-tag>
                </template>
            </el-table-column>
            <el-table-column type="index" align="center" prop="xh" />
            <el-table-column label="案件编号" align="center" prop="ajbh" />
            <el-table-column label="案件名称" align="center" prop="ajmc" />
            <el-table-column label="被取保候审人(被行政拘留人)" align="center" prop="hsr" width="100" />
            <el-table-column label="性别" align="center" prop="xb" />
            <el-table-column label="出生日期" align="center" prop="csrq" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.csrq, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="住址" align="center" prop="zz" width="200" />
            <el-table-column label="户籍地址" align="center" prop="hjdz" width="200" />
            <el-table-column label="单位及职务" align="center" prop="dwzw" width="150" />
            <el-table-column label="联系电话" align="center" prop="lxdh" width="120" />
            <el-table-column label="保证金金额" align="center" prop="sqje" width="100" />
            <el-table-column label="收费方式" align="center" prop="sqfs" />
            <el-table-column label="没收法律文书号" align="center" prop="mswsh" width="150" />
            <el-table-column label="没收金额" align="center" prop="msje" />
            <el-table-column label="没收状态" align="center" prop="mszt">
                <template slot-scope="scope">
                    {{ scope.row.mszt == 0 ? '待没收' : scope.row.mszt == 1 ? '银行未扣款' : scope.row.mszt == 2
                        ? '银行已扣款' : '' }}
                </template>
            </el-table-column>
            <el-table-column label="没收原因" align="center" prop="msyy" />
            <el-table-column label="没收批准时间" align="center" prop="mspzsj" width="180" />
            <el-table-column label="没收填报人" align="center" prop="mstfr" width="100" />
            <el-table-column label="没收日期" align="center" prop="msrq" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.msrq, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="没收填报时间" align="center" prop="mstfsj" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.mstfsj, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="没收审核状态" align="center" prop="msshzt" width="120">
                <template slot-scope="scope">
                    {{ scope.row.msshzt == 0 ? '待没收' : scope.row.msshzt == 1 ? '待审核' : scope.row.msshzt
                        == 2
                        ? '已通过' : scope.row.msshzt == 3 ? '退回' : '' }}
                </template>
            </el-table-column>
            <el-table-column label="没收银行扣款状态 " align="center" prop="mskhzt" width="130">
                <template slot-scope="scope">
                    <span>{{ scope.row.mskhzt ? '已扣款' : '未扣款' }}</span>
                </template>
            </el-table-column>
            <el-table-column label="没收银行扣款时间" align="center" prop="mskhsj" width="180" />
            <el-table-column label="没收银行扣款操作人" align="center" prop="mskhczr" width="150" />
           
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />
        <el-dialog :visible.sync="pdfs" width="45%">
            <div style="display: flex;align-items: center;justify-content: center;">
                <img :src="this.pdfUrl" alt width="80%" />
            </div>
        </el-dialog>
        
    </div>
</template>
  
<script>
import {  downLoadFile,  getFjList, overdueWarning } from "@/api/system/bzjtable";
import selectMultiple from '@/views/collect/addSecurity/selectMultiple'
// import { shBack } from "../../../api/system/bzjtable";
import { blobValidate } from "@/utils/ruoyi";

import XLSX from 'xlsx';//引入
import { saveAs } from 'file-saver'
import pdf from "vue-pdf"
export default {
    name: "Bzjtable",
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            fileList: [],
            directoryList: [],
            fileTableList: [],
            pdfs: false,
            isShow: false,
            dialogFormVisible: false,
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 【请填写功能名称】表格数据
            bzjtableList: [],
            // 弹出层标题
            tit: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                isOverdue: '已超期',
                hsr: null
            },
            pdfUrl: '',
            // formInfo: {},
            wjdz: '',
            // 表单参数
            form: {
                lxdh: '',
                sfzh: '',
                sqtfr: this.$store.state.user.name,
                sqtfsj: this.getNowFormatDate()
            },
            currentIndex: '',
            sytsVisabled: false,
        };
    },
    components: {
        selectMultiple,
        pdf
    },
    created() {
        this.getList();
    },
    methods: {
        /** 查询【请填写功能名称】列表 */
        getList() {
            this.loading = true;
            overdueWarning(this.queryParams).then(response => {
                response.rows.forEach((item, index) => {
                    item.pIndex = index + 1
                })
                this.bzjtableList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.getList();
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                xh: null,
                ajbh: null,
                ajmc: null,
                sqwsh: null,
                hsr: null,
                xjr: null,
                xb: null,
                csrq: null,
                zz: null,
                hjdz: null,
                dwzw: null,
                lxdh: null,
                sfzh: null,
                ajxz: null,
                sqje: null,
                sqfs: null,
                sqzt: null,
                jkr: null,
                jkrsfz: null,
                dsyhbh: null,
                jnsj: null,
                jnkh: null,
                pzr: null,
                pzsj: null,
                bar: null,
                dwbh: null,
                badw: null,
                sqrq: null,
                sqtfsj: this.getNowFormatDate(),
                sqtfr: this.$store.state.user.name,
                msje: null,
                mszt: null,
                msyy: null,
                mswsh: null,
                mspzr: null,
                mspzsj: null,
                mstfr: null,
                msrq: null,
                mstfsj: null,
                msshzt: null,
                mskhzt: null,
                mskhsj: null,
                mskhczr: null,
                thje: null,
                thfs: null,
                thzt: null,
                thrq: null,
                thwsh: null,
                thpzr: null,
                thtfsj: null,
                thshzt: null,
                thshr: null,
                thshsj: null,
                thxm: null,
                thzh: null,
                thkhh: null,
                djzt: null,
                sqdyzt: null,
                djsj: null,
                sqkpzt: null,
                thkpzt: null,
                hbwsh: null,
                hbdw: null,
                hbje: null,
                hbry: null,
                hbrq: null,
                hblxdh: null,
                hbsj: null,
                hbczy: null
            };
            this.resetForm("forms");
        },
        overdueChange(value){
            if(value == '未超期'){
                this.sytsVisabled = true
            }else{
                this.sytsVisabled = false
                this.queryParams.overdueDay = null
            }
        },
        tableRowClassName({ row, column, rowIndex, columnIndex }) {
            //逻辑判断决定是否修改样式，如果分组一致则使用同一个样式
            return row.pIndex == this.currentIndex ? 'hover-bg' : ''
        },
        tableCurrentChange(row) {
            this.form = row
            this.queryParams.xh = row.xh
            this.wjdz = row.wjdz
            this.currentIndex = row?.pIndex
            this.$forceUpdate()
        },
        /** 搜索按钮操作 */
        handleQuery() {
            let ogj = {}
            ogj.xh = this.queryParams.xh
            this.queryParams.pageNum = 1
            if(this.queryParams.isOverdue == '未超期'){
                if(!this.queryParams.overdueDay){
                    this.$modal.msgError("请选择剩余超期天数");
                    return
                }
            }
            this.getList();
        },
        yul(val) {
            downLoadFile({ wjdz: val.wjdz }).then(async (data) => {
                // if (this.wjdz && this.wjdz.split('.')[1] == 'png' || this.wjdz &&this.wjdz.split('.')[1] == 'jpg' || this.wjdz.split('.')[1] == 'jpeg') {
                const url = window.URL.createObjectURL(data);
                this.pdfUrl = url;//直接用iframe标签
                this.pdfs = true
                // }
            })
        },
        handleckfj(row) {
            this.dialogFormVisible = true
            getFjList({ xh: row.xh }).then((res) => {
                this.fileList = res.rows
            })

        },
        handlexzfj(val) {
            // this.download('/confiscate/forfeitureOfDeposit/downLoadFile', { wjdz: this.form.wjdz }, `role_${new Date().getTime()}.png`)
            downLoadFile({ wjdz: val.wjdz }).then(async (data) => {
                this.$modal.msgSuccess("下载成功");
                const url = window.URL.createObjectURL(data);
                this.pdfUrl = url;//直接用iframe标签
                const isBlob = blobValidate(data);
                if (this.wjdz && this.wjdz.split('.')[1] == 'png' || this.wjdz && this.wjdz.split('.')[1] == 'jpg' || this.wjdz && this.wjdz.split('.')[1] == 'jpeg') {
                    if (isBlob) {
                        const blob = new Blob([data])
                        saveAs(blob, `role_${new Date().getTime()}.png`)
                    } else {
                        const resText = await data.text();
                        const rspObj = JSON.parse(resText);
                        const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
                        Message.error(errMsg);
                    }
                } else if (this.wjdz && this.wjdz.split('.')[1] == 'pdf') {
                    // let pdfUrl = window.URL.createObjectURL(new Blob([data], { type: "application/pdf" }));
                    // window.open(pdfUrl)
                    let blob = new Blob([data], { type: 'application/pdf' });
                    let downloadElement = document.createElement("a");
                    let href = window.URL.createObjectURL(blob); //创建下载的链接
                    downloadElement.href = href;
                    downloadElement.download = `pdf下载`    //下载后的文件名，根据需求定义
                    document.body.appendChild(downloadElement);
                    downloadElement.click(); //点击下载
                    document.body.removeChild(downloadElement); //下载完成移除元素
                    window.URL.revokeObjectURL(href); //释放掉blob对象
                } else {
                    const blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) // response就是接口返回的文件流
                    const objectUrl = URL.createObjectURL(blob)
                    const a = document.createElement('a') // 创建a标签
                    a.href = objectUrl
                    a.download = 'excel下载' // 自定义文件名
                    a.click() // 下载文件
                    window.URL.revokeObjectURL(objectUrl) // 释放内存
                    // link.remove()
                }
                this.dialogFormVisible = false
            })
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.queryParams.hsr = ''
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.xh)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
    }
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.creation {
    .el-form-item {
        margin-bottom: 15px;
    }

    ::v-deep.el-input__inner {
        width: 250px;
    }

    .xx {
        ::v-deep.el-input__inner {
            width: 630px;
        }
    }
}

::v-deep .el-table__body-wrapper::-webkit-srollbar-track {
    background-color: rgba(255, 255, 255, 0);
}

//可设置胶囊宽高
::v-deep .el-table__body-wrapper::-webkit-scrollbar {
    height: 12px;
    width: 10px;
    opacity: 0.5;
}

// 设置胶囊色
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
    border-radius: 15px;
    background-color: #cdd9e6;
}

::v-deep .el-table__body .el-table__row.hover-bg td {
    background-color: #cde6f7 !important;
}
</style>